from ECshop.common.base import create_browser,Base
from ECshop.common.base import create_browser_op
import time
class Pageshop_cart(Base):
    url='http://localhost:8080/ecshop/user.php'
    cart_click=('xpath',("//div[@class='cart']/a"))
    # cart_click=('link text','购物车(0)')
    input=('name','keywords')  #左上角输入框
    input_click=('name','imageField')
    clear_click=('class name','bnt_blue_1')
    number_update=('xpath',"//td[@align='right']/input") #
    back_space_number=('class name','inputBg')
    update_click=('name','submit')  #更新按钮
    again_click=('xpath',("//img[@src='themes/default/images/continue.gif']"))
    buy=('xpath',("//td[@align='right']/a/img"))  #结算
    fuz_content=('link text','服装')
    add_pag=('xpath',"//img[@class='goodsimg']")
    add_cart=('xpath',"//img[@src='themes/default/images/buybtn1.png']")  #添加包到购物车
    tijiao=('xpath',"//input[@src='themes/default/images/bnt_subOrder.gif']") #提交

    tijia_is_success=('xpath',"//div[@class='flowBox']/h6") #验证提交
    jiesuan_is_succe=('link text','提交订单')  #验证结算
    again_is_success=('xpath',"//font[@class='f4_b']")  #验证继续购物
    input_is_success=("div[id='ur_here']>div[class='path']>div")
    update_is_success=("div[class='boxCenterList RelaArticle']>div>p") #更新购物车
    add_cart_is_success=('xpath',"//div[@class='cart']/a")
    clear_cart_is_success=('xpath',"//div[@class='cart']/a")  #购物车为零按钮
    delete=('link text','删除')#删除商品按钮
    collection=('link text','放入收藏夹')  #收藏按钮


    #打开网页
    def  page_shop_cart_web(self):
        self.base_open_web(self.url)
    #点击购物车
    def page_shop_cart_click(self):
        self.base_click(self.cart_click)
    #点击服装
    def page_shop_cart_add_click(self):
        self.base_click(self.fuz_content)
    #点击商品
    def page_shop_cart_add_pag(self):
        self.base_click(self.add_pag)
    #加入购物车
    def page_shop_cart_add(self):
        self.base_click(self.add_cart)

    #点击输入框
    def page_shop_cart_input(self,your_content):
        self.base_input_content(self.input,your_content)
    #点击输入框按钮
    def page_shop_cart_input_click(self):
        self.base_click(self.input_click)
    #点击清空购物车
    def page_shop_cart_clear(self):
        self.base_click(self.clear_click)
    #点击输入框
    def page_shop_cart_number_input(self):
        self.base_click(self.number_update)
    #清空修改商品数量的输入框
    def page_shop_cat_clear(self):
        self.base_input_clear(self.number_update)
    #修改购物车数量
    def page_shop_cart_number(self,your_conter):
        self.base_input_content(self.number_update,your_conter)

    #删除商品
    def page_shop_cart_delete(self):
        self.base_click(self.delete)

    #弹窗点击确定删除商品
    def page_shop_cart_sure_delete(self):
        self.base_alert()
    #点击取消删除商品
    def page_shop_cart_no_delete(self):
        self.base_alert_dismiss()


    #点击放入收藏夹
    def page_shop_cart_collection(self):
        self.base_click(self.collection)
    # 点击确定移除商品,加入收藏夹
    def page_shop_cart_sure_collection(self):
        self.base_alert()
    #点击取消放入收藏夹
    def page_shop_cart_no_sure_collection(self):
        self.base_alert_dismiss()

    #验证确定收藏
    def page_shop_cart_sure_collection_is_success(self):
        result = self.base_get_text(self.clear_cart_is_success)
        return result
    #验证取消收藏
    def page_shop_cart_no_sure_collection_is_success(self):
        result = self.base_get_text(self.clear_cart_is_success)
        return result

    #点击更新购物车
    def page_shop_cart_update(self):
        self.base_click(self.update_click)
    #继续购物
    def page_shop_cart_again_shpo(self):
        self.base_click(self.again_click)
    #点击结算
    def page_shop_cart_buy(self):
        self.base_click(self.buy)
    #点击提交订单
    def page_shop_cart_tijiao(self):
        self.base_click(self.tijiao)
    #验证结算
    def page_shop_cart_tijiao_sussecc(self):
        result=self.base_get_text(self.jiesuan_is_succe)
        return result
    #滚动条操作
    def page_shop_cart_roll(self):
        self.base_roll(self.tijiao)
    #验证继续购物按钮
    def page_shop_cart_again_success(self):
        result=self.base_get_text(self.again_is_success)
        return result
    #验证输入框
    def page_shop_cart_input_success(self):
        result = self.base_get_text1(self.input_is_success)
        return result
        # 验证输入框
    #验证更新购物车
    def page_shop_cart_update_success(self):
        result = self.base_get_text1(self.update_is_success)
        return result
    #验证添加购物车是否成功
    def page_shop_cart_add_is_success(self):
        result=self.base_get_text(self.add_cart_is_success)
        return result
    #验证清空购物车
    def page_shop_cart_clear_cart_is_success(self):
        result=self.base_get_text(self.clear_cart_is_success)
        return result
    """确定弹窗"""
    #验证确认删除商品
    def page_shop_cart_sure_delete_is_success(self):
        result = self.base_get_text(self.clear_cart_is_success)
        return result

    #验证取消删除
    def page_shop_cart_no_delete_is_success(self):
        result=self.base_get_text(self.clear_cart_is_success)
        return result



    def page_shop_cart_quit(self):
        self.base_quit()




if __name__ == '__main__':
    p1=Pageshop_cart(create_browser_op(r'C:\Users\86183\AppData\Local\Google\Chrome\User Data'))

    p1.page_shop_cart_web()
    p1.page_shop_cart_click()  #点击购物车
    p1.page_shop_cart_add_click() #点击服装按钮(购物车添加商品)
    p1.page_shop_cart_add_pag()  #点击包
    p1.page_shop_cart_add()  #加入购物车
    # time.sleep(5)
    #点击修改数量输入框
    # p1.page_shop_cart_number_input()
    # time.sleep(5)
    """清空"""
    # p1.page_shop_cart_clear()
    # time.sleep(5)
    """修改数量"""
    # time.sleep(5)
    # p1.page_shop_cart_number('0') #修改数量0
    time.sleep(8)
    p1.page_shop_cart_update() #更新购物车
    # time.sleep(8)
    # """搜索框"""
    # time.sleep(5)
    # p1.page_shop_cart_input('包')
    # p1.page_shop_cart_input_click()

    """继续购物"""
    # time.sleep(5)
    # p1.page_shop_cart_again_shpo()  #继续购物

    """去结算"""
    # p1.page_shop_cart_buy()
    # time.sleep(5)
    # p1.page_shop_cart_roll() #滚动条的操作
    # time.sleep(5)
    #验证结算
    # print(p1.page_shop_cart_tijiao_sussecc())
    #
    # """提交"""
    # p1.page_shop_cart_tijiao()

    """验证提交是否成功"""
    # p1.page_shop_cart_tijiao_sussecc()
    """验证继续更新按钮是否成功"""
    # print(p1.page_shop_cart_update_success())
    # print(p1.page_shop_cart_input_success())
    # print(p1.page_shop_cart_again_success())
    # print(p1.page_shop_cart_update_success())
    # print(p1.page_shop_cart_add_is_success())

    """删除商品"""
    # p1.page_shop_cart_delete()
    # time.sleep(8)
    # # p1.page_shop_cart_sure_delete()
    # # time.sleep(5)
    # # p1.page_shop_cart_delete_is_success()
    # # p1.page_shop_cart_no_delete()
    # # print(p1.page_shop_cart_sure_delete_is_success())
    # # print(p1.page_shop_cart_no_delete_is_success())
    #
    # p1.page_shop_cart_collection()
    # time.sleep(5)
    # # p1.page_shop_cart_sure_collection_is_success()
    # # p1.page_shop_cart_no_sure_c0llection()
    # p1.page_shop_cart_sure_delete()
    # time.sleep(5)
    # # print(p1.page_shop_cart_sure_collection_is_success())
    # print(p1.page_shop_cart_sure_delete_is_success())













